package com.kavenka.zhufengfm.app.utils;

/**
 * Created by kavenka on 2015/9/27 0027.
 */
/**
 * 加密、解密工具类<br/>
 * 包含:<br/>
 * <ul>
 * <li>Hex 编解码</li>
 * <li>Base64 编解码</li>
 * <li>AES 加密</li>
 * <li>RSA 加密</li>
 * <li>DES 加密</li>
 * </ul>
 */
public class EncryptUtil {
    public EncryptUtil() {
    }

    /**
     * 将字节数组中的每一个字节，装换为十六进制字符串
     * @param data
     * @return
     */
    public static String toHex(byte[] data) {
        String ret = null;
        if (data != null) {
            StringBuilder sb = new StringBuilder();
            for (byte b : data) {
                int h, l;
                h = (b >> 4) & 0x0f;
                l = b & 0x0f;
                char ch, cl;
                if(h > 9){
                    ch = (char)('A' + (h - 10));
                }else{
                    ch = (char)('0' + h);
                }
                if(l > 9){
                    cl = (char)('A' + (l - 10));
                }else{
                    cl = (char)('0' + l);
                }
                sb.append(ch).append(cl);
            }
            ret = sb.toString();
            sb = null;
        }
        return ret;
    }
}
